﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameObjectUtil
{
    public static Image createImageWithSprite(string imgSpriteResPath)
    {
        Image image;
        var sprite = Resources.Load<Sprite>(imgSpriteResPath);          //"Imgs/Dog"
        LogUtils.debug("PlaneController Start() sprite = " + sprite);

        if (sprite)
        {
            image = new GameObject("image").AddComponent<Image>();
            //mImage.rectTransform.SetParent(_parentTransform);
            image.sprite = sprite;
            image.SetNativeSize();                                      //设置为图片原始的大小
            image.rectTransform.sizeDelta *= image.canvas.scaleFactor;  //image.canvas.scaleFactor 是获取当前分辨率的缩放比，整行代码是为了分辨率适配
            return image;
        }
        return null;
    }

}
